package com.work.ygj.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.work.ygj.common.model.Response;
import com.work.ygj.common.model.page.PageResult;
import com.work.ygj.entity.GcType;
import com.work.ygj.pojo.dto.GcTypeDto;
import com.work.ygj.pojo.vo.GcTypeVo;
import com.work.ygj.service.GcTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import com.work.ygj.controller.BaseController;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *  垃圾信息分类管理(管理员)(用户只能看列表)
 *
 * @author ygj
 * @since 2022-03-27
 */
@Controller
@RequestMapping("/gcType")
@ResponseBody
public class GcTypeController extends BaseController {

    @Autowired
    private GcTypeService gcTypeService;

    /**
     * 垃圾信息分类列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public Response<PageResult<GcTypeVo>> selectList(@RequestBody GcTypeDto dto){
        return Response.success(getDataTable(gcTypeService.selectList(dto)));
    }

    /**
     * 新增垃圾信息分类信息
     *
     * @param req
     * @return
     */
    @PostMapping("/save")
    public Response save(@RequestBody GcType req) {
        gcTypeService.save(req);
        return Response.success();
    }


    /**
     * 修改垃圾信息分类信息
     *
     * @param req
     * @return
     */
    @PostMapping("/update")
    public Response update(@RequestBody GcType req) {
        UpdateWrapper<GcType> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", req.getId());
        gcTypeService.update(req, updateWrapper);
        return Response.success();
    }

    /**
     * 删除垃圾信息分类记录
     *
     * @param req
     * @return
     */
    @PostMapping("/del")
    public Response del(@RequestBody GcType req) {
        GcType entity = new GcType();
        entity.setId(req.getId());
        entity.setDeleted("1");
        gcTypeService.updateById(entity);
        return Response.success();
    }

    /**
     * 垃圾信息分类信息详情
     *
     * @param req
     * @return
     */
    @PostMapping("/detail")
    public Response<GcType> detail(@RequestBody GcType req) {
        GcType entity = gcTypeService.getById(req.getId());
        return Response.success(entity);
    }
}

